package ms.unicorn.modellanguage;


import ms.unicorn.Element;
import ms.unicorn.diagram.edit.commands.EntityCreateCommand;
import ms.unicorn.util.FigureConstant;

import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gmf.runtime.common.core.command.ICommand;
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.NonResizableEditPolicyEx;
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;

public class LanguageEntityEditHeperAdvice extends LanguageElementEditHelperAdvice implements FigureConstant {	
	public static final LanguageEntityEditHeperAdvice DefaultInstance = new LanguageEntityEditHeperAdvice();

	public ICommand getCreationCommand(LanguageElement element,
			CreateElementRequest req) {
		return new EntityCreateCommand(req);
	}
	
	@Override
	public EditPolicy createPrimaryDragEditPolicy(Element element, EditPart editPart) {
		if (!isResizeable(element))
			return new NonResizableEditPolicyEx();
		return null;
	}
	
	protected boolean isResizeable(Element element) {
		LanguageElement langElement = LanguageRegistry.INSTANCE.getLanguageElement(element);
		if (langElement instanceof LanguageEntity)
			return ((LanguageEntity) langElement).isResizeable();
		return true;
	}

	public boolean acceptChildren(LanguageElement element) {
		return false;
	}
}
